/**
 * creation: 11-mrt-2008
 */
package org.jfonia.connect.arithmetic;

import java.util.ArrayList;

import org.jfonia.connect.BasicNode;
import org.jfonia.connect.Value;

/**
 * @author wijnand.schepens@gmail.com
 *
 */
public class IntMinimum extends BasicNode implements Value<Integer>
{
	protected ArrayList<Value<Integer> > sourceList = new ArrayList<Value<Integer> >();
	
	public IntMinimum() 
	{}

	// convenience:
	public IntMinimum(Value<Integer> v1, Value<Integer> v2) 
	{
		addSource(v1);
		addSource(v2);
	}

	public IntMinimum(Value<Integer> v1, Value<Integer> v2, Value<Integer> v3) 
	{
		addSource(v1);
		addSource(v2);
		addSource(v3);
	}

	public void addSource(Value<Integer> source)
	{
		sourceList.add(source);
	}
	
	public Integer get()
	{
		int min = Integer.MAX_VALUE;
		for (Value<Integer> source: sourceList)
			min = Math.min(source.get(), min);
		return min;
	}

}
